import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;


public class TestBorders {

	static Border emptyBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
	static Border bevelBorder = BorderFactory.createLoweredBevelBorder();
	static TitledBorder titledBorder = BorderFactory.createTitledBorder("Titled border");
	static TitledBorder containerBorder = BorderFactory.createTitledBorder(bevelBorder, "Container");

	// Add a panel with 50 panels inside
	private static JPanel addCompForBorder() {
		JPanel containerPanel = new JPanel(new GridLayout(0,10), false);
		containerPanel.setPreferredSize(new Dimension(640, 400));
		containerPanel.setBorder(titledBorder);
		JPanel containers[] = new JPanel[50];
		int i;
		for (i = 0; i < 50; i++) {
			containers[i] = new JPanel(false);
			containers[i].setBorder(containerBorder);
			containerPanel.add(containers[i]);
		}
		return containerPanel;
	}
	
	private static void createAndShowGUI() {
		JFrame frame = new JFrame("TestJFrame");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// Add a panel with border
		JPanel panel = new JPanel(new BorderLayout(), false);
		panel.setBorder(emptyBorder);
		panel.add(addCompForBorder(), BorderLayout.CENTER);
		
		// Add Accept and Cancel buttons
		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		buttonPanel.add(new JButton("Accept"));
		buttonPanel.add(new JButton("Cancel"));
		panel.add(buttonPanel, BorderLayout.SOUTH);

		// Add a menu bar on top
		panel.add(new JLabel("Menu"), BorderLayout.NORTH);
		
		frame.getContentPane().add(panel);
		
		// Pack and center
		frame.pack();
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setLocation((dim.width - frame.getWidth())/2, (dim.height - frame.getHeight())/2);
		frame.setMinimumSize(new Dimension(frame.getWidth(), frame.getHeight()));

		// Show the GUI
		frame.setVisible(true);
	}
	
	public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

}
